<?php
/**
 * Desc：字段基础类
 * Author：Fly
 * DateTime：2020/9/12 11:02
 */

namespace FlyToper\PearBackend\headers;

use FlyToper\PearBackend\Utils;

class Field
{
    public $field;
    public $title;
    public $conf = [];

    public function __construct($field = '', $title = '')
    {
        $this->field = $field;
        $this->title = $title;
    }

    public function setConf($k, $v = '')
    {
        Utils::setConf($k, $v, $this->conf);
        return $this;
    }

    /**
     * 宽度
     * @param $w
     * @return $this
     */
    public function width($w)
    {
        return $this->setConf('width', $w);
    }

    /**
     * 最小宽度
     * @param $w
     * @return $this
     */
    public function minWidth($w)
    {
        return $this->setConf('minWidth', $w);
    }

    /**
     * 是否可排序（前端排序）
     * @param bool $v
     * @return $this
     */
    public function sortable($v = true)
    {
        return $this->setConf('sort', $v);
    }

    /**
     * 固定列
     * @param string $f
     * @return $this
     */
    public function fixed($f = 'left')
    {
        if($f != 'left') {
            $f = 'right';
        }

        return $this->setConf('fixed', $f);
    }
}